/*
 * @Author: your name
 * @Date: 2021-09-02 09:18:03
 * @LastEditTime: 2021-09-02 18:50:15
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \briup\5-javascript\day09\1-String.js
 */

var s = 'hello';
console.log(s.length); //5
//charAt(i) 返回给定位置的字符
console.log(s.charAt(1)); //e
console.log(s.charCodeAt(1)); //101

console.log(s.indexOf("e")); //1
console.log(s.indexOf("q")); //-1
//lastIndexOf 从后往前找，找到了也是原来字符所在位置
console.log(s.lastIndexOf("e")); //1
console.log(s.indexOf("l", 2)); //2
console.log(s.indexOf("e", 2)); //-1

//concat() 字符串拼接
var s2 = ",world";
console.log(s.concat(s2));

//slice() 字符串拼接方法  [start_index,end_index)
var s = "helloworld";
console.log(s);
var s1 = s.slice(2, 5);
console.log(s1); //llo
console.log(s);

//substr() 截取指定字符串  (start_index length)
console.log(s.substr(3, 7)); //loworld

//substring() 截取字符串 和slice一样
console.log(s.substring(2, 5)); //llo

//trim() 删除字符串前后空格
var s = " hello world ";
console.log(s.trim());
console.log(s);

// toUpperCase() 转为大写方法
var s = " hello world ";
console.log(s.toUpperCase());
console.log(s);

//toLowerCase() 转为小写方法
var s = " HELLO WORLD "
console.log(s.toLowerCase());
console.log(s);
//abs绝对值
var result = Math.abs(-10);
console.log(result); //10
//
var date = new Date("1990/12/1");
var count = date.setHours(16);
var date2 = new Date(count);
console.log(date2.toLocaleString());
console.log(count, date2.getTime());